﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System.Media;
using Microsoft.Xna.Framework.Media;

namespace Erebos.CreditsScreenFiles
{
    class CreditsScreen : Screen
    {
        private string _text;
        private float _delay = ScreenSizeHelper.SizeHeight;

        public CreditsScreen()
        {
            _text = "REMOVED";

            MediaPlayer.Play(MainGame.Songs["Final Count"]);
        }

        public override void Update(GameTime gameTime)
        {
            int zeilenCount = _text.Split(new string[] { Environment.NewLine }, 100, StringSplitOptions.None).Length;
            if (_delay <= 0 - zeilenCount * 26 - 10)
            {
                MainGame.SetScreen(new TrittEinScreenFiles.TrittEinScreen());
                MediaPlayer.Stop();
            }
            else
                _delay -= gameTime.ElapsedGameTime.Milliseconds * 0.04f;

            base.Update(gameTime);
        }

        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            int i = 0;
            foreach (string s in _text.Split(new string[] { Environment.NewLine }, 100, StringSplitOptions.None))
            {
                if (!s.StartsWith("&b") && !s.StartsWith("&c"))
                {
                    int size = (int)MainGame.Fonts["Arial16"].MeasureString(s).X;
                    int posX = ScreenSizeHelper.SizeWidth / 2 - size / 2;
                    spriteBatch.DrawString(MainGame.Fonts["Arial16"], s, new Vector2(posX, 0 + i * 26 + _delay), Color.White);
                }
                else if (s.StartsWith("&c"))
                {
                    string ss = s.Replace("&c", "");
                    int size = (int)MainGame.Fonts["Arial24Bold"].MeasureString(ss).X;
                    int posX = ScreenSizeHelper.SizeWidth / 2 - size / 2;
                    spriteBatch.DrawString(MainGame.Fonts["Arial24Bold"], ss, new Vector2(posX + 1, 1 + i * 26 + _delay), Color.Gray);
                    spriteBatch.DrawString(MainGame.Fonts["Arial24Bold"], ss, new Vector2(posX, 0 + i * 26 + _delay), Color.Goldenrod);
                }
                else
                {
                    string ss = s.Replace("&b", "");
                    int size = (int)MainGame.Fonts["Arial18Bold"].MeasureString(ss).X;
                    int posX = ScreenSizeHelper.SizeWidth / 2 - size / 2;
                    spriteBatch.DrawString(MainGame.Fonts["Arial18Bold"], ss, new Vector2(posX + 1, 1 + i * 26 + _delay), Color.Gray);
                    spriteBatch.DrawString(MainGame.Fonts["Arial18Bold"], ss, new Vector2(posX, 0 + i * 26 + _delay), Color.White);
                }
                i++;
            }
            base.Draw(spriteBatch, gameTime);
        }
    }
}
